package com.jp.java8;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

public class MethodReference {

    public static void main(String[] args) {
        Consumer<String> consumer = (str)->System.out.println(str);

        useConsumer(consumer,"str");
        useConsumer(System.out::println,"str");

        Function<String ,Integer> function = Integer::parseInt;
        Integer result = function.apply("123");
        System.out.println(result);

        BiFunction<String, Integer, Character> f2 = String::charAt;
        char c = f2.apply("abc",1);
        System.out.println(c);

        String string = new String("hello");
        Function<Integer, Character> f3 = string::charAt;
        char c1 = f3.apply(1);
        System.out.println(c1);

        Supplier<String> s = String::new;
        String str = s.get();
        System.out.println(str);

        BiFunction<String,Integer,Apple> bi = Apple::new;
        Apple a = bi.apply("color",100);
        System.out.println(a);

        ThreeFunction<String ,Integer, String, ComplexApple> f4 = ComplexApple::new;
        ComplexApple complexApple = f4.function("color",100,"name");
        System.out.println(complexApple);

        List<Apple> list1= Arrays.asList(new Apple("a",1));
        list1.sort(Comparator.comparing(Apple::getColor));

    }


    private static <T> void useConsumer(Consumer<T> consumer, T t){
        consumer.accept(t);
        consumer.accept(t);
    }
}
